package shared.net.protocol;

import java.util.HashMap;

/**
 * Each message received and sent by the server will have a header attached
 * to identify the kind of message in the packet. This class defines the
 * various headers.
 * 
 * ** Implementation Note: All headers are from the server's perspective.
 *
 * @author Vincent Tsuei
 * @author Andrew Gratta
 * @version 11-21-2012
 */
public final class ServerHeader {

    public enum Receive {

        PONG,              
        MENU_REQUEST,
        LOGIN_REQUEST,     
        DISCONNECT_REQUEST, 
        GAME_LIST_REQUEST,  
        PLAYER_LIST_REQUEST,
        NEW_GAME_REQUEST,
        PLAYER_MOVE_REQUEST,
        OBSERVE_GAME_REQUEST,
        UNOBSERVE_GAME_REQUEST,
        FORFEIT_GAME_REQUEST;
        
        private static final HashMap<Byte, Receive> ByteToRecv = new HashMap<>();

        static {
            for (Receive r : Receive.values()) {
                ByteToRecv.put((byte) r.ordinal(), r);
            }
        }

        public byte getHeaderAsByte() {
            return (byte) this.ordinal();
        }

        public static Receive getHeaderFromByte(int b) {
            return ByteToRecv.get((byte) b);
        }
    }

    public enum Send {

        PING,
        MENU_RESPONSE, 
        LOGIN_RESPONSE,  
        GAME_INVITE_NOTIFY,
        GAME_START_NOTIFY, 
        GAME_UPDATE, 
        NEW_GAME_RESPONSE, 
        GAME_END_NOTIFY, 
        OBSERVE_GAME_RESPONSE, 
        OBSERVE_GAME_UPDATE,
        OBSERVE_GAME_END_NOTIFY,
        GAME_LIST_RESPONSE, 
        PLAYER_LIST_RESPONSE; 
        
        private static final HashMap<Byte, Send> ByteToSend = new HashMap<>();

        static {
            for (Send r : Send.values()) {
                ByteToSend.put((byte) r.ordinal(), r);
            }
        }

        public byte getHeaderAsByte() {
            return (byte) this.ordinal();
        }

        public static Send getHeaderFromByte(int b) {
            return ByteToSend.get((byte) b);
        }
    }
}
